// 商品分类管理
import request from "@/utils/request";

import type {
    pmsCategoriesResponse,
    pmsCategorResponse,
    pmsCategoryEditResponse,
    pmsCategorySortType,
    pmsCategoryType
} from "./types";

enum API {
    PMS_CATEGORY_LIST_TREE = "pms/category/list/tree",
    PMS_CATEGORY_CREATE_OR_EDIT = "pms/category/createOrEdit",
    PMS_CATEGORY_REMOVE = "pms/category/remove",
    PMS_CATEGORY_GET_BY_ID = "pms/category/getById",
    PMS_CATEGORY_UPDATE_SORT = "pms/category/updateSort",
}

export const pmsCategoryListTree = () => request.get<any, pmsCategoriesResponse>(API.PMS_CATEGORY_LIST_TREE);

export const pmsCategoryCreateOrEdit = (data: pmsCategoryType) =>
    request.post<any, pmsCategoryEditResponse>(API.PMS_CATEGORY_CREATE_OR_EDIT, data);

export const pmsCategoryRemove = (id: number) =>
    request.delete<any, pmsCategoryEditResponse>(API.PMS_CATEGORY_REMOVE + `/${id}`);

export const pmsCategoryGetById = (id: number) =>
    request.get<any, pmsCategorResponse>(API.PMS_CATEGORY_GET_BY_ID + `/${id}`);

export const pmsCategoryUpdateSort = (data: pmsCategorySortType) =>
    request.post<any, pmsCategoryEditResponse>(API.PMS_CATEGORY_UPDATE_SORT, data);
